package sz.szsmk.citizencard.ui.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.LayoutHelper;
import com.alibaba.android.vlayout.layout.DefaultLayoutHelper;
import com.bumptech.glide.Glide;

import java.util.ArrayList;
import java.util.List;

import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.databinding.ApphomeModuleCultureViewBinding;
import sz.szsmk.citizencard.databinding.ApphomeModuleFinanceViewBinding;
import sz.szsmk.citizencard.model.network.bean.response.HomeWeathRes;
import sz.szsmk.citizencard.model.network.clarkbean.response.AdInfo;
import sz.szsmk.citizencard.model.network.clarkbean.response.AreaInfo;

/**
 * Copyright (c)2020
 * author: clark
 * created on: 2020年10月7日 16点07分
 * description: App首页文化模块
 */
public class AppHomeCultureAdapter extends DelegateAdapter.Adapter<AppHomeCultureAdapter.AppHomeCultureHolder> {
    private Context mContext;
    private LayoutHelper mGridLayoutHelper;
    private ArrayList<Integer> iconList = new ArrayList<>();
    private AreaInfo viewData;
    private BaseInterface baseInterface;


    public interface BaseInterface {
        public void onClick(View view, String url, String syslabl, int need_header, String id, AdInfo bean);
    }

    public void setBaseInterface(BaseInterface baseInterface) {
        this.baseInterface = baseInterface;
    }

    public AppHomeCultureAdapter(FragmentActivity activity, DefaultLayoutHelper headHelper) {
        mContext = activity;
        mGridLayoutHelper = headHelper;

    }

    @Override
    public LayoutHelper onCreateLayoutHelper() {
        return mGridLayoutHelper;
    }

    @Override
    public AppHomeCultureHolder onCreateViewHolder(ViewGroup parent, int viewType) {
//        View view = LayoutInflater.from(mContext).inflate(R.layout.apphome_head_view_new, parent, false);
        return  AppHomeCultureHolder.creat(parent);
    }

    @Override
    public int getItemViewType(int position) {
        return R.layout.apphome_module_culture_view;
    }

    @Override
    public void onBindViewHolder(AppHomeCultureHolder holder, int position) {
//        holder.blurringView.setBlurredView();

        if (viewData != null) {
            holder.binding.cultureTitle.setText(viewData.getResource_area_name());
//            Glide.with(mContext)
//                    .load(viewData.getAdInfoVoList().get(0).getResource_url())
//                    .into(holder.binding.cultureImg1);
//            Glide.with(mContext)
//                    .load(viewData.getAdInfoVoList().get(1).getResource_url())
//                    .into(holder.binding.cultureImg2);
//            Glide.with(mContext)
//                    .load(viewData.getAdInfoVoList().get(2).getResource_url())
//                    .into(holder.binding.cultureImg3);
//            loadItemData(position, holder.binding);
            holder.binding.cultureImg1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Log.d("clark","culture click");
                    AdInfo adInfo=viewData.getAdInfoVoList().get(0);
                    baseInterface.onClick(v, adInfo.getLink_url(), adInfo.getSys_label(),
                            adInfo.getNeed_header(), adInfo.getResource_id()+"",viewData.getAdInfoVoList().get(0));
                }
            });


            holder.binding.cultureImg2.setOnClickListener(v -> {
                AdInfo adInfo=viewData.getAdInfoVoList().get(1);
                baseInterface.onClick(v, adInfo.getLink_url(), adInfo.getSys_label(),
                        adInfo.getNeed_header(), adInfo.getResource_id()+"",viewData.getAdInfoVoList().get(1));
            });
            holder.binding.cultureImg3.setOnClickListener(v->{
                AdInfo adInfo=viewData.getAdInfoVoList().get(2);
                baseInterface.onClick(v, adInfo.getLink_url(), adInfo.getSys_label(),
                        adInfo.getNeed_header(), adInfo.getResource_id()+"",viewData.getAdInfoVoList().get(2));
            });


        }
    }

    private void loadItemData(int position, ApphomeModuleCultureViewBinding binding) {
        if(position==0){
            Log.d("clark culture position",viewData.getAdInfoVoList().get(position).getResource_url());
        }
    }

    @Override
    public int getItemCount() {
        return 1;
    }


    public void setViewData(AreaInfo viewData) {
        this.viewData = viewData;
        for(int i=0;i<viewData.getAdInfoVoList().size();i++){
            Log.d("clark culture",viewData.getAdInfoVoList().get(i).getResource_url());
        }
    }


    public static class AppHomeCultureHolder extends RecyclerView.ViewHolder {
        private ApphomeModuleCultureViewBinding binding;

        public static AppHomeCultureHolder creat(ViewGroup parent) {
            ApphomeModuleCultureViewBinding binding =
                    ApphomeModuleCultureViewBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);

            return new AppHomeCultureHolder(binding);
        }
//        private final BlurringView blurringView;
//        private final TextView weatherTtemp;
//        private final TextView weatherAir;
////        private final TextView tem;
//        private final RelativeLayout weatherLayout;
//        private final EditText search_et;

        public AppHomeCultureHolder(ApphomeModuleCultureViewBinding binding) {
            super(binding.getRoot());

//            blurringView = (BlurringView) itemView.findViewById(R.id.blurring_view);
////            weath1 = (TextView) itemView.findViewById(R.id.home_weath);
//
//            weatherTtemp = (TextView) itemView.findViewById(R.id.weather_temp_text);
//            weatherAir = (TextView) itemView.findViewById(R.id.weather_air);
//
//            weatherLayout = (RelativeLayout) itemView.findViewById(R.id.layout_weather);
//            search_et = (EditText) itemView.findViewById(R.id.search_et);

            this.binding = binding;
        }

    }

}
